package com.hfzy.ihk.web.userCenter.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hfzy.ihk.facade.userCenter.entity.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用于集成spring security Mapper 接口
 * </p>
 *
 * @author wws
 * @since 2018-12-28
 */
public interface RoleMapper extends BaseMapper<Role> {

    int count(@Param("params") Map<String, Object> params);

    List<Role> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset,
                    @Param("limit") Integer limit);

    @Select("select * from role t where t.role_name = #{name}")
    Role getRole(String name);



    @Delete("delete from user_has_role where role_Id = #{roleId}")
    int deleteUserHasRoleByRoleId(Long roleId);


    int saveRoleHasPriv(@Param("roleId") Long roleId, @Param("privIds") List<Long> privIds);


    @Select("select r.* from role r inner join user_has_role uhr  on uhr.role_id= r.id where uhr.user_id=#{userId}")
    List<Role> getRoleByUserId(int userId);


}
